<?php
//订单模型
namespace Admin\Model;
use Think\Model;

/**
 * 模型
 */
class moneylogModel extends Model{
    
    protected $tableName = 'moneylog';

    /**
     * 自动完成
     * @var array
     */
    protected $_auto = array(
    );


    /*
     * 自动验证
     */
    protected $_validate = array(
     );
    
    /*
     * 获取列表
     */
    public function getMoneylogList($where,$page){
        //TODOTODO
        $res = $this->where($where)->order("log_id DESC")->page($page,100)->select();
        return $res;
    }
    
    /*
     * 获取列表
     */
    public function getMoneylogList2($where,$page){
        //TODOTODO
        $res = $this->where($where)->order("log_id DESC")->page($page,5000)->select();
        return $res;
    }
    
    /*
     * 获取列表,不分页
     */
    public function getMoneylogLists($where){
        //TODOTODO
        $res = $this->where($where)->select();
        return $res;
    }
    
    /*
     * 统计数量
     */
    public function getMoneylogCount($where){
        $res = $this->where($where)->count();
        return $res;
    }
    
    /*
     * 添加
     */
    public function addMoneylog($data){
        $res = $this->add($data);
        return $res;
    }
    
    /*
     * 获取信息
     */
    public function getMoneylog($where){
        $res = $this->where($where)->find();
        return $res;
    }
	
    /*
     * 编辑信息
     */
    public function editMoneylog($where,$data){
        return $this->where($where)->save($data);
    }
    
    /*
     * 计算昨天的各类奖金
     * $type 1分销佣金,2重消币 ,3现金电子币 ,4重消佣金,5互助奖,6车房奖, 7领导奖, 8分红奖 ,9保证金 , 10个税 , 11提货币流
     * $logtype类型: 1收入,0支出
     */
    public function sumJiangjin($type){
        $where = array(
            'mtype' => $type,
            'logtype' => 1,
        );
        $start = date("Y-m-d",strtotime("-1 day")).' 00:00:00';
        $end = date("Y-m-d").' 00:00:00';
        $time = "create_time>='".$start."'";
        $time .= " AND create_time<='".$end."'";
        $res = $this->where($time)->where($where)->sum('money');
        return $res;
    }
    
    
    
}
